package com.wrox.todolist;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;

public class TodoItemView extends TextView {
	private Paint marginPaint, linePaint;
	private int paperColor;
	private float margin;
	private boolean finished = false;
	
	public TodoItemView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init();
	}

	public TodoItemView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	public TodoItemView(Context context) {
		super(context);
		init();
	}

	private void init() {
		Resources r = this.getResources();
		marginPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
		marginPaint.setColor(r.getColor(R.color.notepad_margin));
		linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
		linePaint.setColor(r.getColor(R.color.notepad_lines));
		paperColor = r.getColor(R.color.notepad_paper);
		margin = r.getDimension(R.dimen.notepad_margin);
	}

	@Override
	protected void onDraw(Canvas canvas) {
		canvas.drawColor(paperColor);
		canvas.drawLine(0, 0, 0, this.getMeasuredHeight(), linePaint);
		canvas.drawLine(0, getMeasuredHeight(), getMeasuredWidth(), getMeasuredHeight(), linePaint);
		canvas.drawLine(margin, 0, margin, getMeasuredHeight(), marginPaint);
		if (finished)
			canvas.drawLine(margin, getMeasuredHeight()/2, getMeasuredWidth(), getMeasuredHeight()/2, linePaint);
		canvas.save();
		canvas.translate(margin, 0);
		super.onDraw(canvas);
		canvas.restore();
	}

	public void setFinished(boolean finished) {
		this.finished = finished;
	}

	
}
